package com.clear.proxy.dynamicProxy.cglib;

import org.springframework.cglib.proxy.Enhancer;

public class Main {
    public static void main(String[] args) {
        // cglib通过Enhancer
        Enhancer enhancer = new Enhancer();
        // 设置它的父类
        enhancer.setSuperclass(DatabaseDataQuery.class);
        // 设置一个方法拦截器，用来拦截方法
        enhancer.setCallback(new CacheMethodInterceptor());
        // 创建代理类
        DatabaseDataQuery dataQuery = (DatabaseDataQuery) enhancer.create();

        System.out.println(dataQuery.query("key1"));
        System.out.println("--------------------");
        System.out.println(dataQuery.query("key1"));
        System.out.println("--------------------");
        System.out.println(dataQuery.query("key2"));

        System.out.println("==============================");
        System.out.println(dataQuery.queryAll("key1"));
        System.out.println("--------------------");
        System.out.println(dataQuery.queryAll("key1"));
        System.out.println("--------------------");
        System.out.println(dataQuery.queryAll("key2"));

    }
}
